class Solution {
    public:
        long long mostPoints(vector<vector<int>>& questions) {
            int n = questions.size();
            vector<long long> memo(n);
            auto dfs = [&](this auto&& dfs, int i) -> long long {
                if (i >= n) {
                    return 0;
                }
                long long& res = memo[i]; // 注意这里是引用
                if (res) { // 之前计算过
                    return res;
                }
                return res = max(dfs(i + 1), dfs(i + questions[i][1] + 1) + questions[i][0]);
            };
            return dfs(0);
        }
    };